<?php
namespace app\api\controller;
use app\api\model\User;
use app\api\model\Agency;
use think\Controller;

class Myself extends Controller{
    public function information(){
        $id = input('id');
        $user = new User;
        $results = $user->information($id);
        AjaxReturn('1','成功',['results'=>$results]);
    }

    /**
     * 修改个人信息(头像)
     */
    public function rechangeP(){
        $id = input('id');
        $photo=request()->file('photo');
        //$photo = input('photo');
        $user = new User();
        $data = $user->rechangePh($id,$photo);
        if($data==1){
            AjaxReturn('1','修改成功',['results'=>$data]);
        }elseif($data==2){
            AjaxReturn('10006','图片丢失,修改失败');
        }else{
            AjaxReturn('10007','异常错误,修改失败');
        }
    }

    /**
     * 修改个人信息（用户名/昵称）
     */
    public function rechangeN(){
        $id   = input('id');
        $name = trim(input('name'));
        $user = new User();
        $data = $user->rechangeNa($id,$name);
        if($data){
            AjaxReturn('1','修改成功',['results'=>$data]);
        }
        else{
            AjaxReturn('10007','异常错误,修改失败');
        }
    }
    //我的店铺
    public function myshop(){
        $id   = input('id');
        $agent = new Agency();
        $results = $agent->myshop($id);
        if($results){
            AjaxReturn('1','成功',['results'=>$results]);
        }
        else{
            AjaxReturn('10035','店铺信息获取失败');
        }
    }
}